home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Science / Gnuplot 3.5 / docs / doc2gih.c < prev    next >
C/C++ Source or Header  |  1993-11-03  |  2KB  |  104 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: doc2gih.c%v 3.38.2.70 1993/02/08 02:19:29 woo Exp woo $";
  3. #endif
  4.  
  5.  
  6. /*
  7.  * doc2gih.c  -- program to convert Gnuplot .DOC format to gnuplot
  8.  * interactive help (.GIH) format.
  9.  *
  10.  * This involves stripping all lines with a leading digit or
  11.  * a leading @, #, or %.
  12.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  13.  *
  14.  * usage:  doc2gih [file.doc [file.gih]]
  15.  *
  16.  * Original version by David Kotz used the following one line script!
  17.  * sed '/^[0-9@#%]/d' file.doc > file.gih
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <ctype.h>
  22.  
  23. #define MAX_LINE_LEN    256
  24. #define TRUE 1
  25. #define FALSE 0
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char **argv;
  30. {
  31. FILE * infile;
  32. FILE * outfile;
  33.     infile = stdin;
  34.     outfile = stdout;
  35.     if (argc > 3) {
  36.         fprintf(stderr,"Usage: %s [infile [outfile]]\n", argv[0]);
  37.         exit(1);
  38.     }
  39.     if (argc >= 2) 
  40.         if ( (infile = fopen(argv[1],"r")) == (FILE *)NULL) {
  41.             fprintf(stderr,"%s: Can't open %s for reading\n",
  42.                 argv[0], argv[1]);
  43.             exit(1);
  44.         }
  45.     if (argc == 3)
  46.         if ( (outfile = fopen(argv[2],"w")) == (FILE *)NULL) {
  47.             fprintf(stderr,"%s: Can't open %s for writing\n",
  48.                 argv[0], argv[2]);
  49.         }
  50.     
  51.     convert(infile,outfile);
  52.     exit(0);
  53. }
  54.  
  55.  
  56. convert(a,b)
  57.     FILE *a,*b;
  58. {
  59.     static char line[MAX_LINE_LEN];
  60.  
  61.     while (fgets(line,MAX_LINE_LEN,a)) {
  62.        process_line(line, b);
  63.     }
  64. }
  65.  
  66. process_line(line, b)
  67.     char *line;
  68.     FILE *b;
  69. {
  70.     static int line_count = 0;
  71.  
  72.     line_count++;
  73.  
  74.     switch(line[0]) {        /* control character */
  75.        case '?': {            /* interactive help entry */
  76.           (void) fputs(line,b); 
  77.           break;        
  78.        }
  79.        case '@': {            /* start/end table */
  80.           break;            /* ignore */
  81.        }
  82.        case '#': {            /* latex table entry */
  83.           break;            /* ignore */
  84.        }
  85.        case '%': {            /* troff table entry */
  86.           break;            /* ignore */
  87.        }
  88.        case '\n':            /* empty text line */
  89.        case ' ': {            /* normal text line */
  90.           (void) fputs(line,b); 
  91.           break;
  92.        }
  93.        default: {
  94.           if (isdigit(line[0])) { /* start of section */
  95.                   /* ignore */
  96.           } else
  97.             fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
  98.                 line[0], line_count);
  99.           break;
  100.        }
  101.     }
  102. }
  103.  
  104.